#ifndef FENETRE_H
#define FENETRE_H

#include <QWidget>
#include <QApplication>
#include <QMessageBox>
#include <list>
#include <sstream>
#include "QSFMLCanvas.hpp"
#include "configgame.h"
#include "defaultscreen.h"
#include "salonscreen.h"
#include "MyCanvas.h"
#include "mythread.h"
#include "client.h"
#include "Etat.h"
#include "Carte.hpp"

namespace Ui {
    class Fenetre;
}

typedef struct
{
    std::string nom;
} MyClient;

typedef struct
{
    std::string nom;
    sf::Uint8 nbJoueursAct;
    sf::Uint8 nbJoueursMax;
} MyGame;

enum eScreen
{
    eDEF = 1,
    eCFG = 2,
    eSAL = 3,
    eCANV = 4
};

class DefaultScreen;
class ConfigGame;
class salonScreen;

class Fenetre : public QWidget
{
    Q_OBJECT
    
public:
    explicit Fenetre(Client* c, MyThread* mt, QWidget *parent = 0);
    ~Fenetre();

    void addText(QString q);
    void addClient(QString q);
    void addPartie(QString q);
    void refreshClients();
    void refreshGames();

    void deleteScreenAct();

public slots:
    // slots main
    void quitter();
    void lineChatReturn();
    void newClient(QString);
    void newGame(QString, int, int);
    void newMsg(QString);
    void decoClient(QString);
    void decoGame(QString);
    void slotRetourMenu();
    void createGame();
    void joinGame();
    void traitementJoinGame(int);
    void sendNewGame();
    void traitementCreateGame(int);
    void slotAddPartie(QString);
    void slotRmPartie(QString);
    void slotQuitSalon();
    void slotSalQuit();

    // slots partie
    void slotReady();
    void slotDatasGame(int, int);
    void slotAddPoint(int, int);
    void slotIdJoueur(int);
    void slotLaunch();
    void addClientSalon(QString);
    void rmClientSalon(QString);
    void traitementChangeEtat(int);
    void traitementSelectionT(int, int);
    void traitementTMaj(int, int, int, int);
    void traitementWin(QString);
    
private:
    Ui::Fenetre *ui;
    DefaultScreen* defScreen;
    ConfigGame* cfgGame;
    salonScreen* salScreen;
    MyCanvas* canvasSfml;

    MyThread* _mythread;

    Client* _client;

    std::list<MyClient> clients;
    std::list<MyGame> games;

    std::list<MyClient> clientsSalon;

    eScreen scrAct;

    void closeEvent(QCloseEvent *event);

    std::vector<std::pair<int, int> > centres;
    int nbJ;
    int nbTparJ;

    Carte* map;
    Camp* camps;

    int idJoueur;
    int etat;
};

#endif // FENETRE_H
